<?php
namespace app\web\controller;

use app\model\Record; 
use app\model\Util; 
use app\model\Theme as Theme_mod;
use app\model\Poster; 
use app\model\Order; 

class Theme extends Base
{
    public function Theme()
    {
global $_G, $_P;

$op = !empty($_P['op']) ? $_P['op'] : 'display';
// if($op !== 'display'){
// 	if (strstr($_SERVER['HTTP_HOST'],".y.yixuan.net")!==false){
// 	    return_msg('请不要使用管理网址操作!');
// 	}
// }

//load_func('tpl');
if (!empty($_P['themeid'])) {
            $system = $_G['system'];
        } else {
            $moduleslist = Modules::getCurrentModuleAllTheme();
            $system = $moduleslist[0]['system'];
        }
$serverconfigs = db_find("SELECT * FROM ".tablename('00serverconfig')." WHERE id =1 ");
$system['s']  = !empty($serverconfigs['settings']) ? xunserializer($serverconfigs['settings']) : array();   

$title = "活动";
$_G['page']['title'] = $title.'列表-' . $system['title'];
$id = intval ( $_P['id'] );
$do = 'theme';
$themeid = $id;
$GLOBALS['frames'] = array();
$url = createWebUrl($do, array('op' => 'display'));
//$key = $_G['setting']['site']['key'];
$auth['error'] = 0;
$cachekey = MODULE_NAME.'theme'.$_G['mpid'].'-'.$id;
if ($op =='viewtuwen') {
	$logsql = "SELECT * FROM " . tablename ( t_log ) . " WHERE id=" . $_P['logid'] . " and uniacid = '" . $_G['mpid'] . "' ORDER BY id desc";
	$log = db_find ( $logsql );
}

if($op == "sendnotify"){
	$r = db_update(t_fans,array('msgstatus'=>0), array("themeid" => $themeid, "sublive" => "1"));
    $c = Theme_mod::getConfig($themeid);
    $c ['livedata']['sendnotify'] = 1;
    Theme_mod::setConfig($c,$themeid,$_G['mpid']);
}

// if ($system['gongzhong'] =='1'){
// 	$domaintxt = $system['domainhead1'];
// }else{
	$domaintxt = DOMAIN0;
// }
//判断是否有人在编辑中
$sql = "SELECT * FROM " . tablename(t_theme) . " 
                where uniacid = :uniacid and status <> '-1' ORDER BY id desc limit 1";
$theme = db_find($sql, array(":uniacid"=>$_G['mpid']));
if (empty($theme) && $system['adminname'] != $_G['username'] && !empty($system['adminname']) && $system['admintime'] > strtotime("-1 day")){

	$_end_time = strtotime("+1 day",$system['admintime']);
	$_start_time = TIMESTAMP;
	$_timestamp = $_end_time-$_start_time;
	$_days = floor($_timestamp / 86400);
	$_hous = floor($_timestamp % 86400 / 3600);
	$_mintues = floor($_timestamp % 86400 % 3600 / 60);
	$_secode = floor($_timestamp % 86400 % 3600 % 60);
	$timetxt = $system['adminname'] . "正在编辑中，还需要等待" . "${_hous}小时${_mintues}分钟${_secode}秒";
}
$theme = "";

if ($system['hdget']==1 && $_G['isSuperAdmin']) {
	$themetips = "此链接部分数据，来自【".substr($system['hdsourceurl'],-7)."】" ;
}
if (!empty($system['tiaozhuanurl'])) {
	if (stripos($system['tiaozhuanurl'],'跳转至')!==false) {
		$timetxt = "此链接已失效，所有活动已".$system['tiaozhuanurl'] ;
	}else{
		$timetxt = "此活动已设置跳转至".$system['tiaozhuanurl'] ;
	}	
}


if($op == 'display'){
//$_G['user']["founder_groupid"]
//$_G['isSuperAdmin'] && !user_is_vice_founder()
//新版概率随机
	$pageNumber = max ( 1, intval ( $_P['page'] ) );
	$pageSize = 10;
    //$condition = "s.uniacid = '{$_G['mpid']}'";
	// if($_G['role'] == 'clerk'){
	// 	$condition.= " and s.uid='{$_G['uid']}' ";
	// }
	// $keyword = $_P['keyword'];
	// if(!empty($keyword)){
	// 	$condition.= " and s.title like '%{$keyword}%'";
	// }

	$condition = "status <> '-1' ";
    $total = Theme_mod::getTotal($condition);
    if ($_G['username']=='benben' || $_G['username']=='caiwu' || $_G['username']=='chuna') {
    	$condition2 = "status = '-1' ";
    	$deltotal = Theme_mod::getTotal($condition2);
    }
    if ($_P['status']=='-1') {
    	$condition = "status = '-1' ";
    }

 //    if ($total == 1 && ($_G['username']=='caiwu' || $_G['username']=='chuna') && empty($_P['cw'])) {
 //    	$themeid = Theme_mod::getDefaultThemenew();
 //    	$theme = Theme_mod::getThemeById($themeid);
 //    	if (!empty($theme['softsn'])) {
	//     	$url =   $_G['siteroot'].createWebUrl('bill', array('themeid'=>$themeid));
	// 		echo "<script language='javascript' type='text/javascript'>";
	// 		echo "window.location.href='$url';"; 
	// 		echo "</script>";  
	// 		exit;
 //    	}
	// }

	$logsql = "SELECT * FROM " . tablename ( t_log )  . " ORDER BY id desc limit 10";
	$log = db_select ( $logsql );

	$logsql = "SELECT type,count(id) as shuliang FROM " . tablename ( t_log ) . " group by type ORDER BY type asc";
	$loglist = db_select ( $logsql );

	$logsql = "SELECT COUNT(*) FROM " . tablename ( t_log ) . " ORDER BY id desc ";
    $alltotal = db_fetchcolumn ($logsql);

	// $logsql = "SELECT * FROM " . tablename ( t_log ) . " WHERE  type = '导出数据'  ORDER BY id desc";
	// $log1 = db_select ( $logsql );

	// $logsql = "SELECT * FROM " . tablename ( t_log ) . " WHERE  type <> '导出数据' and tuwen is null ORDER BY id desc";
	// $log2 = db_select ( $logsql );

	// $logsql = "SELECT * FROM " . tablename ( t_log ) . " WHERE  type <> '导出数据' and tuwen<>'' ORDER BY id desc";
	// $log3 = db_select ( $logsql );
	
	// if ($_G['username']=='benben') {
	// 	$log = array_merge($log1,$log3);
	// 	$log = array_merge($log,$log2);
	// }else{
	// 	$log = array_merge($log3,$log1);
	// 	$log = array_merge($log,$log2);
	// }

    $list = Theme_mod::getList($condition,$pageNumber,$pageSize);
	foreach ($list as $index =>$row){
		$list[$index]['recordcount'] = intval(db_fetchcolumn ( 'SELECT COUNT(*) FROM ' . tablename ( t_record ) . "
				WHERE themeid = '{$row['id']}' and status > 0  and status!=3" ));
		$list[$index]['fanscount'] = intval(db_fetchcolumn ( 'SELECT COUNT(*) FROM ' . tablename ( t_fans ) . "
				WHERE themeid = '{$row['id']}' " ));
		$list[$index]['ordercount'] = floatval(db_fetchcolumn ( 'SELECT sum(realfee) FROM ' . tablename ( t_order ) . "
				WHERE themeid = '{$row['id']}' and paystate = 1 and realfee > 0 " ));
		$list[$index]['ordercount'] = sprintf("%.2f", $list[$index]['ordercount']);

		$list[$index]['commcount'] = floatval(db_fetchcolumn ( 'SELECT sum(fee) FROM ' . tablename ( t_comm ) . "
            WHERE themeid ='{$row['id']}'  and status  = 1 " ));
		$list[$index]['commcount'] = -sprintf("%.2f", $list[$index]['commcount']);

		if ($row['uniacid'] != $_G['mpid']){
			$sql = "SELECT w.uniacid,w.name FROM " . tablename('account_wechats') . " as w
			where w.uniacid = ". $row['uniacid'] ."  order by w.uniacid";
			$accountlist = db_find($sql);
			if (empty($accountlist)) {
				$sql = "SELECT w.uniacid,w.name FROM " . tablename('account_wxapp') . " as w
				where w.uniacid = ". $row['uniacid'] ."  order by w.uniacid";
				$accountlist = db_find($sql);
				$list[$index]['accountname'] = $accountlist['name'];
			}else{
				$list[$index]['accountname'] = $accountlist['name'];
			}
		}

        // $list[$index]['replysum'] = Reply::getNumByThemeId($row['id']);
        

        if (abs($list[$index]['recordcount']-$row['recordcount'])>30) {
			$p = array(":themeid"=>$row['id']);
        	db_query("UPDATE ".tablename(t_theme)." SET fanscount = '" . $list[$index]['fanscount'] . "',recordcount = '" . $list[$index]['recordcount'] . "',ordercount = '" . $list[$index]['ordercount'] . "',commcount = '" . $list[$index]['commcount'] . "' WHERE id =:themeid",$p);
		}
        
        //更新报表并获取最新报名
        $list[$index]['report'] = Theme_mod::renewreport($row['id']);

        if  ($system['wxapp']==0 || $system['softmode']!=1){
        	$config = Theme_mod::getConfig($row['id']);
	        if (empty($config['indexurl'])) {
				$indexurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('index',array('themeid'=>$row['id']));
				$indexurl = Poster::GetMainUrl($system,$indexurl,MODULE_NAME . '主网址');

				$dapingurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('w_daping',array('themeid'=>$row['id']));
				$dapingurl = Poster::GetMainUrl($system,$dapingurl,MODULE_NAME . '添加投屏网址');
				if (!empty($row['softsn'])) {
					$addworkerurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('w_init',array('themeid'=>$row['id']));
					$addworkerurl = Poster::GetMainUrl($system,$addworkerurl,MODULE_NAME . '添加员工网址');
				}

				$config['indexurl'] = $indexurl;
				$config['dapingurl'] = $dapingurl;
				$config['addworkerurl'] = $addworkerurl;
				Theme_mod::setConfig($config,$row['id'],$row['uniacid']);
	        }else{
	        	$indexurl = $config['indexurl'];
	        }
	    }
	    if ($system['wxapp']!=0 && $system['softmode']!=0) {
        	$config = Theme_mod::getConfig($row['id']);
	        if (empty($config['indexurlxcx'])) {
                $scene = MODULE_NAME . "-" . $row['id'] . "-0-" . $row['softkey'] ;
                $indexurlxcx = Poster::CreateScene($system,$scene,'pages/index/index');

//              $scene = "?softname=" . MODULE_NAME . "&themeid=" . $row['id'] . "&softkey=" . $row['softkey'] ;
//	            $indexurlxcx = Poster::CreateXcxqr($system,'','pages/index/index' . $scene);
	            if (!empty($row['softsn'])) {
                    $addworkerurl = Poster::CreateScene($system,$scene,'pages/w_init/w_init');
//		            $addworkerurl = Poster::CreateXcxqr($system,'','pages/w_init/w_init' . $scene);
				}
				$dapingurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('w_daping',array('themeid'=>$row['id']));
				$dapingurl = Poster::GetMainUrl($system,$dapingurl,MODULE_NAME . '添加投屏网址');
				$config['indexurlxcx'] = $indexurlxcx;
				$config['dapingurlxcx'] = $dapingurl;
				$config['addworkerurlxcx'] = $addworkerurl;
				Theme_mod::setConfig($config,$row['id'],$_G['mpid']);
	        }else{
	        	$indexurlxcx = $config['indexurlxcx'];
	        }
	    }

	    $list[$index]['indexurl'] =$indexurl;
	    $list[$index]['indexurlxcx'] =$indexurlxcx;
	}
	$pager = pagination ( $total, $pageNumber, $pageSize );
}
if ($op == 'deletenew') {
	$theme = Theme_mod::getById($id);
	if($_G['role'] == 'clerk'){
        return_tips ( '无权限操作，请联系管理员！' );
	}
    Theme_mod::update($id,array('status' =>-1));
    //cache_clean();
	return_tips ( '删除成功！', createWebUrl('theme', array('op'=>'display')), 'success' );
}
if ($op == 'qrnew') {
	$theme = Theme_mod::getById($id);
	$config = Theme_mod::getConfig($id);
	    // if ($system['wxapp']==0) {
			$indexurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('index',array('themeid'=>$id));
			$indexurl = Poster::GetMainUrl($system,$indexurl,MODULE_NAME . '主网址');

			$dapingurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('w_daping',array('themeid'=>$id));
			$dapingurl = Poster::GetMainUrl($system,$dapingurl,MODULE_NAME . '添加投屏网址');
			if (!empty($theme['softsn'])) {
				$addworkerurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('w_init',array('themeid'=>$id));
				$addworkerurl = Poster::GetMainUrl($system,$addworkerurl,MODULE_NAME . '添加员工网址');
			}
			$config['indexurl'] = $indexurl;
			$config['dapingurl'] = $dapingurl;
			$config['addworkerurl'] = $addworkerurl;
			// Theme_mod::setConfig($config,$id,$_G['mpid']);
	    // }else{
            $scene = MODULE_NAME . "-" . $theme['id'] . "-0-" . $theme['softkey'] ;
            $indexurl = Poster::CreateScene($system,$scene,'pages/index/index');
//            $scene = "?softname=" . MODULE_NAME . "&themeid=" . $theme['id'] . "&softkey=" . $theme['softkey'] ;
//            $indexurl = Poster::CreateXcxqr($system,'','pages/index/index' . $scene);
            if (!empty($theme['softsn'])) {
                $addworkerurl = Poster::CreateScene($system,$scene,'pages/w_init/w_init');
//            	$addworkerurl = Poster::CreateXcxqr($system,'','pages/w_init/w_init' . $scene);
            }
			$dapingurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('w_daping',array('themeid'=>$id));
			$dapingurl = Poster::GetMainUrl($system,$dapingurl,MODULE_NAME . '添加投屏网址');
			$config['indexurlxcx'] = $indexurl;
			$config['dapingurlxcx'] = $dapingurl;
			$config['addworkerurlxcx'] = $addworkerurl;
			Theme_mod::setConfig($config,$id,$_G['mpid']);

	return_tips ( '重置成功', createWebUrl('theme', array('op'=>'display')), 'success' );
}
if ($op == 'deleteben') {
	$theme = Theme_mod::getById($id);
	if($_G['username']!=='benben'){
        return_tips ( '无权限操作，请联系管理员！' );
	}
    Theme_mod::delete($id);
    db_delete (t_log, array('themeid'=>$id));
	return_tips ( '删除成功！', createWebUrl('theme', array('op'=>'display')), 'success' );
}

if ($op == 'renew') {
	$theme = Theme_mod::getById($id);
	if($_G['role'] == 'clerk'){
        return_tips ( '无权限操作，请联系管理员！' );
	}
    Theme_mod::update($id,array('status' =>1));
    //cache_clean();
	return_tips ( '还原成功！', createWebUrl('theme', array('op'=>'display')), 'success' );
}

if ($op == 'dellog') {
    db_delete (t_log, array('type'=>"开发调试"));
    db_delete (t_log);
	return_tips ( '删除成功', createWebUrl('theme', array('op'=>'display')), 'success' );
}
// if($op == 'copy') {
//     $theme = Theme_mod::getById($id);
//     if(empty($theme)) {
//         return_tips('不存在或已删除', referer(), 'error');
//     }
//     $config = 	Theme_mod::getConfig($id);
//     unset($theme['id']);
//     unset($theme['scansum']);
//     $theme['title']  = $theme['title'] . '- 复制';
//     $theme['status'] = 0;
//     $theme['scansum'] = 0;
//     $insertid = db_insert(t_theme, $theme);
//     $theme_id = $insertid;
//     Theme_mod::setConfig($config, $theme_id);
//     return_tips('复制成功', createWebUrl($do, array('op' => 'post','id' => $theme_id)), 'success');
// }


// if($op == 'status') {
// 	$status = intval($_P['status']);
// 	db_update(t_theme, array('status' => $status), array('uniacid' => $_G['mpid'], 'id' => $id));
//     //cache_clean();
// 	return_tips(error(0, ''), '', 'ajax');
// }

if($op == 'post'){

	if (!empty($timetxt)) {
		return_msg("无法新增活动，".$timetxt);
	}
	if ( $system['s']['isaddtheme']!=1 && $id == 0 ) {
		return_msg("此服务器暂停新增活动");
	}
	// if (!checksubmit ()) {
	// 	//http://oa.yixuan.net/app/index.php?i=2&c=entry&do=getbanklist&m=yx99999&op=getserverinfo
	// 	$serverinfo = Poster::Getbanklist($system,'getserverinfo','');
	// 	if (empty($serverinfo) || $serverinfo['error'] != 0) {
	// 		echo "加载服务器参数失败";
	// 	}else{
	// 		//加载音乐
	// 		$musiclist = $serverinfo['musiclist'];
	// 		foreach ($musiclist as $index => $item) {
	// 	        $listtxt ="";
	// 	        $listlink ="";
	// 	        if (!empty($item['list'])) {
	// 		        foreach ($item['list'] as $key => $value) {
	// 		            if ($key==0) {
	// 		                $listtxt = "'" . $value['name'] . "'";
	// 		                $listlink = "'" . $value['link'] . "'";
	// 		            }else{
	// 		                $listtxt .= ",'". $value['name'] . "'";
	// 		                $listlink .= ",'". $value['link'] . "'";
	// 		            }
	// 		        }
	// 	        }
	// 	        $musiclist[$index]['listname'] = $listtxt;
	// 	        $musiclist[$index]['listlink'] = $listlink;
	// 	    }
	//         //加载标签
	// 		$softtaglist = $serverinfo['softtag'];
	// 	}
	// }
		$softtaglist = array();
		$softtaglist[0] = explode(",",$system['s']['softtag0']);
		$softtaglist[1] = explode(",",$system['s']['softtag1']);
		$softtaglist[2] = explode(",",$system['s']['softtag2']);
		
		$musiclist = db_select ( "SELECT * FROM " . tablename ( "00musiclist" ) . " ORDER BY id");


		if ($system['gift']==1 || $system['fanpai']==1) {
			$groupsql = "SELECT * FROM " . tablename ( t_giftgroup ) . " WHERE state = 1 ORDER BY id";
			$grouplist = db_select ( $groupsql );
		}

		// if ($system['ruanjian']==3) {
			$shoplist = db_select ( "SELECT * FROM " . tablename (t_shangjia) .
					" WHERE state = 1 order by displayorder" );
		// }

		$starttime =db_fetchcolumn ( 'SELECT min(addtime) FROM ' . tablename ( t_fans ) );
		if ($system['tuwen']==0 && $starttime > 0 && $starttime<strtotime('-5 day') || $system['tuwen']==2) {
			$isold = true;
		}
		$themelist = Theme_mod::getAllTheme();
		
	if ($id > 0) {
        $poster =  Poster::getByThemeIdnew($id,1);
        if(!empty($poster['id'])){
            $isposter=true;
        }else{
            $isposter=false;
        }

        $theme = Theme_mod::getById($id);
	    $theme_old = $theme;
		if (empty($theme)) {
			return_tips ( '抱歉，信息不存在或是已经删除！', '', 'error' );
		}

	    $config = 	Theme_mod::getConfig($id);
		if (empty($config['bannerimgs']) && !empty($config['headlogo'])) {
			$config['bannerimgs'][0] =$config['headlogo'];
		}

	    $config_old = $config;
	    if ($system['wxapp']==0 || $system['softmode']!=1) {
		    if (!empty($config['addworkerurl'])) {
		    	$indexurl = $config['indexurl'];
		    	$dapingurl = $config['dapingurl'];
		    	$addworkerurl = $config['addworkerurl'];
		    }else{
				$indexurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('index',array('themeid'=>$id));
				$indexurl = Poster::GetMainUrl($system,$indexurl,MODULE_NAME . '主网址');

				$dapingurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('w_daping',array('themeid'=>$id));
				$dapingurl = Poster::GetMainUrl($system,$dapingurl,MODULE_NAME . '添加投屏网址');
				if (!empty($theme['softsn'])) {
					$addworkerurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('w_init',array('themeid'=>$id));
					$addworkerurl = Poster::GetMainUrl($system,$addworkerurl,MODULE_NAME . '添加员工网址');
				}
				$config['indexurl'] = $indexurl;
				$config['dapingurl'] = $dapingurl;
				$config['addworkerurl'] = $addworkerurl;
				Theme_mod::setConfig($config,$id,$_G['mpid']);
		    	$config = 	Theme_mod::getConfig($id);
		    	$config_old = $config;
			}
	    }
	    if ($system['wxapp']!=0 && $system['softmode']!=0) {
		    if (!empty($config['addworkerurlxcx'])) {
		    	$indexurlxcx = $config['indexurlxcx'];
		    	$dapingurl = $config['dapingurl'];
		    	$addworkerurlxcx = $config['addworkerurlxcx'];
		    }else{
                $scene = MODULE_NAME . "-" . $id . "-0-" . $theme['softkey'] ;
                $indexurlxcx = Poster::CreateScene($system,$scene,'pages/index/index');

//              $scene = "?softname=" . MODULE_NAME . "&themeid=" . $id . "&softkey=" . $theme['softkey'] ;
//	            $indexurlxcx = Poster::CreateXcxqr($system,'','pages/index/index' . $scene);

	            if (!empty($theme['softsn'])) {
                    $addworkerurlxcx = Poster::CreateScene($system,$scene,'pages/w_init/w_init');
//	            	$addworkerurlxcx = Poster::CreateXcxqr($system,'','pages/w_init/w_init' . $scene);
					$config['addworkerurlxcx'] = $addworkerurlxcx;
	            }
				$dapingurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('w_daping',array('themeid'=>$id));
				$dapingurl = Poster::GetMainUrl($system,$dapingurl,MODULE_NAME . '添加投屏网址');
				$config['indexurlxcx'] = $indexurlxcx;
				$config['dapingurl'] = $dapingurl;
				Theme_mod::setConfig($config,$id,$_G['mpid']);
		    	$config = 	Theme_mod::getConfig($id);
		    	$config_old = $config;
			}
			$xcxurl = 'pages/index/index?softname=' . MODULE_NAME . '&themeid=' . $id . '&softkey=' . $theme['softkey'];
	    }
	    if (!empty($theme['softsn'])) {
		    if ($system['wxapp']==0 || $system['softmode']!=1) {
				if ($system['tixing']==1 && $theme['status']==1) {
					if (!empty($config['addworker_qrimg1'])) {
				    	$addworker_qrimg = $config['addworker_qrimg1'];
				    }else{
						//易宣服务器
						$data = array(
							'server'  => DOMAIN0,
							'softname'  => MODULE_NAME,
					        'uniacid' 	=> $_G['mpid'],
							'themeid' 	=> $id,
							'softkey' 	=> $theme['softkey'],
							'title' 	=> $theme['title'],
							'company' 	=> $theme['jubf'],				
							'desc' 	=> $theme['desc'],
							'endtime' 	=> $theme['endtime'],
							'headlogo' 	=> $theme['headlogo'],
						);
						$qr = Poster::ServerQR($system,'get',$data);
					    $addworker_qrimg = $qr['qrimg'];
				    }
				    $addworker_qrimg1 = $addworker_qrimg;
				}elseif ($system['tixing']==3 && $theme['status']==1) {
					if (!empty($config['addworker_qrimg2'])) {
				    	$addworker_qrimg = $config['addworker_qrimg2'];
				    }else{
						//客户公众平台
					    $qr = getQR($system,$domaintxt,$themeid,$theme['softkey']); 
					    $addworker_qrimg = $qr['qrimg_addworker'];
					    if (is_error($qr)) {
					        $result['code'] = 0;
					        $result['message'] = $qr["message"];
					        die(json_encode($result));
					        exit;
					    }
					}
				    $addworker_qrimg2 = $addworker_qrimg;			
				}else{
					$addworker_qrimg = createWebUrl('qr',array('url'=>$addworkerurl));
				}
		    }
		    if ($system['wxapp']!=0 && $system['softmode']!=0) {
		    	$addworker_qrimgxcx = $config['addworkerurlxcx'];
		    }
		    
	    }
		
	    if ($config['zhuandanbegintime']<strtotime("2019-01-01")) {
	    	$config['zhuandanbegintime'] = $theme['endtime'];
	    }
	    if ($config['zhuandanendtime']<strtotime("2019-01-01")) {
	    	$config['zhuandanendtime'] = $theme['endtime'];
	    }
		// $wurl = $_G['siteroot'].createMobileUrl('worker',array('themeid'=>$id));
  //       $orderurl = $_G['siteroot'].createMobileUrl('worker',array('themeid'=>$id,'op'=>'order'));
		// $apiurl.="&code=".MD5($ip)."&themeid=".$id."&uid=".$_G['mpid'];
	}else{
		if (!$_G['isSuperAdmin']){
			return_tips ( '没有权限操作！', '', 'error' );
		}
		if (empty($system['appid'])){
			return_tips ( '请先提交【参数设置】！', $url, 'success' );
		}
		$theme['uniacid'] = $_G['mpid'];
		$theme['begintime'] = strtotime(date('Y-m-d 00:00:00',strtotime('-1 day')));
		$config['yukuantime'] = strtotime(date('Y-m-d 00:00:00',strtotime('-1 day')));
		$theme['endtime']   = strtotime(date('Y-m-d 23:59:59',strtotime('-1 day')));
		$config['zhuandanbegintime'] = strtotime(date('Y-m-d 00:00:00',strtotime('-1 day')));
		$config['zhuandanendtime']   = strtotime(date('Y-m-d 23:59:59',strtotime('-1 day')));
		$config['comm4autoredtime']   = strtotime(date('Y-m-d 23:59:59'));
		$theme['status'] = 1;
		$theme['refundfee'] = 5;
		$config['isrecent'] = 0;
		$config['isrecent'] = 0;
		$config['renshu'] = 0;
		$config['isfreeze']   = 1;
		$config['iscommshow24'] = 1;
		$config['isshowkefu'] = 1;
		$config['touxiang'] = 2;
		$config['automusic'] = 1;
        $config['workerpass'] = 30000+rand(0,9999);
		$config['musicsrc'] = $system['s']['default_mp3'];
		$config['darkicon'] = $system['s']['default_dark'];
		$config['lighticon'] = $system['s']['default_light'];
		$config['iconname'] = '立即点亮小星星';
		$config['iconnum'] = 3;
		$config['iconnum2'] = 1;
		$config['iconlimit'] = 0;
		$config['isshowname'] = 1;
		$config['fcfootmenu'] = 1;
		$config['commlistbg1'] = '#fee567';
		$config['commlistbg2'] = '#fffaef';
		$config['starbgcolor'] = '#ffffff';
		$config['starbtcolor'] = '#fc3611';
		$config['startextcolor'] = '#ffffff';
		$config['formtextleft'] = '￥#dan#br原价购买';
		$config['formtextcenter'] = '￥#fee#br立即抢购';
		$config['formtextcenternew'] = '我要开团';
		$config['formtextright'] = '加入TA的团';
		$config['formtextleftxcx'] = '￥#dan#br原价购买';
		$config['formtextcenterxcx'] = '￥#fee#br立即抢购';
		$config['formtextcenternewxcx'] = '我要开团';
		$config['formtextrightxcx'] = '加入TA的团';
		$config['formtextpay'] = '点击支付报名费#fee元';
		$config['isshowprice'] = '1';
		$config['buttontyle'] = '2';
		$config['formtextleftopen']=1;
		if ($system['ruanjian']==1) {
			$config['isdanmu'] = '2';
		}else{
			$config['isdanmu'] = '1';
		}
		$config['isrank'] = 1;
		$config['isreport'] = 1;
		$config['iseditorder'] = 1;
		$config['isshoprank'] = 1;
		$config['isxianxia'] = 1;	
		$config['comm4type'] = 1;
		$config['comm4typehb'] = 1;	
		$config['comm4typeyg'] = 4;	
		$config['groupneedtime'] = '24';
		//$config['payway'] = '1';
		$config['iconname_menu']='帮TA点亮';
		$config['friend_success'] = '已帮TA点亮';
        $config['friend_name'] = '点亮';
		$config['getavatar'] = 1;
		$config['livedata']['livetime'] =  strtotime(date('Y-m-d 00:00:00',strtotime('-1 day')));

		if ($system['softstyle']==1){
			$config['buttontyle'] = '0';
			$config['formcolorhead']  = "#fed904";
			$config['formcolorcenter']  = "#f36765";
			$config['formcolortop'] = "#ec1f1a";
			$config['formcolorlefttext'] = "#615f5f";
			$config['formcolorcentertext'] = "#ffffff";
			$config['formcolorrighttext'] =  "#ffffff";
			$config['formtextcenter'] = '￥#fee#br立即抢购';
			$config['formtextcenternew'] = '￥#fee#br我要开团';
			$config['formtextright'] = '￥#fee#br加入TA的团';
		}elseif ($system['softstyle']==2){
			$config['buttontyle'] = '0';
			$config['ishexiao'] = '1';
			$config['formtextcenter'] = '抢购';
			$config['lablesuccess'] = '已成功抢购';
			$config['formcolorhead']  = "#4b0";
			$config['formcolorcenter']  = "#f58daf";
			$config['formcolortop'] = "#f70";
			$config['formcolorlefttext'] = "#ffffff";
			$config['formcolorcentertext'] = "#ffffff";
			$config['formcolorrighttext'] =  "#ffffff";			

		}elseif ($system['softstyle']==3){
			$config['formtextleft'] = '￥#dan#br原价购买';
			$config['formtextcenter'] = '￥#tuan#br我要开团';
			$config['formtextcenternew'] = '￥#tuan#br我要开团';
			$config['formtextright'] = '￥#tuan#br一键拼团';
			$theme['isautorefund'] = 1;
			$config['formtextpay'] = '立即支付';
		}elseif ($system['softstyle']==4){
			$config['buttontyle'] = '0';
			$config['ishexiao'] = '1';
			$config['formtextcenter'] = '抢购';
			$config['wtlablesuccess'] = '已成功抢购【 到店核销 】';			
			$config['formcolorhead']  = "#ffbd02";
			$config['formcolorcenter']  = "#f58daf";
			$config['formcolortop'] = "#ff7201";
			$config['formcolorlefttext'] = "#ffffff";
			$config['formcolorcentertext'] = "#ffffff";
			$config['formcolorrighttext'] =  "#ffffff";		
		}elseif ($system['softstyle']==5){
			$config['buttontyle'] = '0';
			$config['formcolorhead']  = "#f44";
			$config['formcolorcenter']  = "#00C4FF";
			$config['formcolortop'] = "#f21212";
			$config['formcolorlefttext'] = "#ffffff";
			$config['formcolorcentertext'] = "#ffffff";
			$config['formcolorrighttext'] =  "#ffffff";
			$config['jmformtextleft'] = '立即免费在线报名';
			$config['formtextcenternew'] = '点击全款加盟';
			$config['jmlablesuccess'] = '恭喜您抢购成功';
			$config['jmkefuimg'] = 'https://css2019.yixuan.net/2019css/jiameng/img/kefu.png';
		}elseif ($system['softstyle']==7){
			$config['isshowtips'] = '1';
			$config['iconlogo'] = '1';
			$config['isicon'] = '1';
			$config['formtextcenter'] = '我要报名';
			$config['iconname'] = '点亮品牌LOGO';
			$config['friendorder'] = 0;
			$config['todayicon'] = 3;
			$config['friend_name'] = '送星星';
			$config['friend_unit'] = '颗星星';
			$config['friend_anniu'] = '点击送星星';
			$config['friend_success'] = '已送TA星星';
			$config['friend_wait'] = 10;
			$config['iconname_menu']='点亮LOGO';
			$config['starbgcolor']='#e1e0de';
			$config['starbtcolor']='#14bbdf';
			$config['sharetip'] = 'https://img2019.yixuan.net/images/2/2019/07/S8mkFKeJeXMnKXErAfeMfYxkLjj0No.png';
			$config['buttontyle'] = 1;

		}
		if ($system['fanpai']==1) {
			$config['fanpaiimg']="https://img2019.yixuan.net/images/2/2019/08/mU22OO2Nw644X01162z4fO8NQo40b2.png";
			$config['fanpaibgcolor'] ="#93beb4";
		}
		if ($system['jiage'] > 0 ) {
			$config['formtextpay'] = '立即支付';
		}
	}
	
	$sql = "SELECT w.uniacid,w.name FROM " . tablename('account_wechats') . " as w
		 order by w.uniacid desc";
	$accountlist = db_select($sql);

	$sql = "SELECT w.uniacid,w.name FROM " . tablename('account_wxapp') . " as w 
		 order by w.uniacid";
	$wxapplist = db_find($sql);

	// var_dump($wxapplist);
	array_push($accountlist,$wxapplist);

	if($_G['role'] != 'clerk'){
        
	}

	if (checksubmit ()) {
		$bannerimgs = $_P['bannerimgs'];
		if (!empty($bannerimgs)) {
			$headlogo = tomedia($bannerimgs[0]);
		}

		$words=explode(",",$system['s']['adkeyword']);
		$res_banned1=Poster::check_words($words,$_P['title']);
		if (!empty($res_banned1)) {
			return_msg('主标题含有违规词：'.implode(',',$res_banned1));
		}
		$res_banned2=Poster::check_words($words,$_P['desc']);
		if (!empty($res_banned2)) {
			return_msg('副标题含有违规词：'.implode(',',$res_banned2));
		}
		$res_banned2=Poster::check_words($words,$_P['sharetitle1']);
		if (!empty($res_banned2)) {
			return_msg('未支付分享标题含有违规词：'.implode(',',$res_banned2));
		}
		$res_banned2=Poster::check_words($words,$_P['sharetitle2']);
		if (!empty($res_banned2)) {
			return_msg('已支付分享标题含有违规词：'.implode(',',$res_banned2));
		}
		if (sprintf("%.2f",floatval($_P['primeprice']))!='0.00') {
			$res_banned2=Poster::check_words($words,$_P['formtextleft']);
			if (!empty($res_banned2)) {
				return_msg('原价购买文字含有违规词：'.implode(',',$res_banned2));
			}
		}
		$res_banned2=Poster::check_words($words,$_P['formtextcenter']);
		if (!empty($res_banned2)) {
			return_msg('按扭文字含有违规词：'.implode(',',$res_banned2));
		}
		$res_banned2=Poster::check_words($words,$_P['formtextcenternew']);
		if (!empty($res_banned2)) {
			return_msg('按扭文字含有违规词：'.implode(',',$res_banned2));
		}
		$res_banned2=Poster::check_words($words,$_P['formtextright']);
		if (!empty($res_banned2)) {
			return_msg('按扭文字含有违规词：'.implode(',',$res_banned2));
		}
		
		if(!empty($_P['comm41'])){
			if(empty($_P['comm4daynum']) || empty($_P['comm4city']) || empty($_P['comm4day']) || empty($_P['comm4hour'])){
				return_msg('开启裂变红包,每天多少个、每天预算、每小时预算、城市四个必填项目必须填!');
			}
		}
		if(!empty($_P['comm51'])){
			if(empty($_P['comm5daynum']) || empty($_P['comm4city']) || empty($_P['comm4day']) || empty($_P['comm4hour'])){
				return_msg('开启阅读红包,每天多少个、每天预算、每小时预算、城市四个必填项目必须填!');
			}
		}
		if(empty($_P['title'])){
			return_msg('名称不可为空');
		}
		if (intval($_P['yukuan']<intval($_P['joinfee'])) && floatval($_P['yukuan'])>0) {
			return_msg('全款金额必须大于定金');
		}
		//判断红包金额
		if (floatval($_P['comm61'])>floatval($_P['comm62']) ) {
			return_msg('员工提成金额设置错误，右边金额必须大于等于左边金额');
		}
		if (floatval($_P['comm11'])>floatval($_P['comm12']) || floatval($_P['comm11_2'])>floatval($_P['comm12_2']) || floatval($_P['comm11_3'])>floatval($_P['comm12_3'])) {
			return_msg('一级分销金额设置错误，右边金额必须大于等于左边金额');
		}
		if (floatval($_P['comm21'])>floatval($_P['comm22']) || floatval($_P['comm21_2'])>floatval($_P['comm22_2'])) {
			return_msg('二级分销金额设置错误，右边金额必须大于等于左边金额');
		}
		if (floatval($_P['comm31'])>floatval($_P['comm32']) || floatval($_P['comm31_2'])>floatval($_P['comm32_2'])) {
			return_msg('三级分销金额设置错误，右边金额必须大于等于左边金额');
		}
		if (floatval($_P['comm41'])>floatval($_P['comm42']) || floatval($_P['comm41_2'])>floatval($_P['comm42_2']) || floatval($_P['comm41_3'])>floatval($_P['comm42_3'])) {
			return_msg('裂变红包金额设置错误，右边金额必须大于等于左边金额');
		}
		if (floatval($_P['comm41'])>floatval($_P['comm42']) || floatval($_P['comm41_2'])>floatval($_P['comm42_2']) || floatval($_P['comm41_3'])>floatval($_P['comm42_3'])) {
			return_msg('裂变红包金额设置错误，右边金额必须大于等于左边金额');
		}


		if (floatval($_P['hbopenfee1'])>floatval($_P['hbopenfee2']) || floatval($_P['hborderfee1'])>floatval($_P['hborderfee2'])) {
			return_msg('红包新玩法金额设置错误，右边金额必须大于等于左边金额');
		}


		$maxcomm1 = max(floatval($_P['comm12']),floatval($_P['comm12_2']),floatval($_P['comm12_3']));
		$maxcomm2 = max(floatval($_P['comm22']),floatval($_P['comm22_2']));
		$maxcomm3 = max(floatval($_P['comm32']),floatval($_P['comm32_2']));
		$maxcomm4 = max(floatval($_P['comm42']),floatval($_P['comm42_2']),floatval($_P['comm42_3']));

		$comm1 = $maxcomm1 + $maxcomm2 + $maxcomm3 + $maxcomm4 +floatval($_P['hbopenfee2'])+floatval($_P['hborderfee2']);
		if (floatval($_P['joinfee'])>0){
			$feepay=floatval($_P['joinfee']);
		}elseif (floatval($_P['groupprice'])>0){
			if ($_P['groupprice']>$_P['groupprice2'] && floatval($_P['groupprice2'])>0){
				$feepay=floatval($_P['groupprice2']);

			}else{
				$feepay=floatval($_P['groupprice']);
			}
		}else{
			$feepay=floatval($_P['primeprice']);
		}
		if ($comm1>$feepay && $feepay>0){
			return_msg('所有分销总金额不能大于支付金额');
		}

		if ((floatval($_P['hbopenfee2'])+floatval($_P['hborderfee2']))>floatval($_P['hbtixian'])){
			return_msg('红包新玩法中：【进入链接获得】+【自己报名获得】必须小于【提现限额】');
		}

		//更新活动时间
		$begintime = strtotime($_P['themetime']['start']);
		$endtime = strtotime($_P['themetime']['end']);
		if (!empty($id)) {
			if (DOMAIN0 != "30.yixuan.net") {
		        if ($theme['endtime']<strtotime("-90 day")) {
				    if ($_G['username']!=='benben') {
				        return_msg('活动结束超3个月,无法编辑');
				    }
				}elseif ($theme['endtime']<strtotime("-30 day")) {
				    if ($_G['username']!=='benben' && $_G['username']!=='caiwu' && $_G['username']!=='chuna') {
				        return_msg('活动结束超1个月,无法编辑');
				    }
				}
			}


			$theme = Theme_mod::getThemeById($id);
			if ($theme['endtime']-$theme['begintime'] < 60*60*24){
				if ( $endtime > $begintime+60*60*24){
					$begintime = $begintime+60*60*24;
				}
			}
			//更新日报表数据库
	        $todaytime =$begintime ;
	        while ($todaytime <$endtime) {
	            $today = date('Y-m-d',$todaytime);
	            $sql = "SELECT * FROM " . tablename ( t_report ) . " WHERE software = '".MODULE_NAME."' and themeid = '{$id}' and riqi = '" .$today ."'";
	        	$daylist = db_find($sql);
	        	if (empty($daylist)) {
	        		$data = array(
                    	'software' => MODULE_NAME,
	                    'uniacid' => $_G['mpid'] , 
	                    'themeid' => $themeid , 
	                    'riqi' => $today , 
	                    'renewtime' => 0 , 
	                ); 
	                $insertid = db_insert(t_report,$data);
	            }
	            $todaytime = $todaytime + 60*60*24;
	        }
		}elseif ( $endtime > $begintime+60*60*24){
			$begintime = $begintime+60*60*24;
		}
		if ($_G['isSuperAdmin']) {
			if (!empty($_P['softtag0'])) {
				$softtag0 = implode(",",$_P['softtag0']);
			}
			if (!empty($_P['softtag1'])) {
			$softtag1 = implode(",",$_P['softtag1']);
			}
			if (!empty($_P['softtag2'])) {
			$softtag2 = implode(",",$_P['softtag2']);
			}
		}else{
			$softtag0 = $config['softtag0'];
			$softtag1 = $config['softtag1'];
			$softtag2 = $config['softtag2'];
		}
		$data = array (
			//基本设置
			'indexno'     => intval($_P['indexno']),
			'title'       => $_P['title'],
			'desc'        => $_P['desc'],
			'keyword'     => $softtag0 . "," . $softtag1 . "," . $softtag2,
			'img'         => tomedia($_P['img']),
			'begintime'   => $begintime,
			'endtime'     => $endtime,
			'status'      => intval($_P['status']),
			'blacklist'        => $_P['blacklist'],
		);

		if (($isold && $_G['isSuperAdmin']) || !$isold) {
			if (strstr($headlogo,".jpeg")!==false ){
				return_msg('活动主图文件格式错误！');
			}
			$data['headlogo'] = tomedia($headlogo);
			$data['addimg'] = tomedia($_P['addimg']);
			$data['addimgxcx'] = tomedia($_P['addimgxcx']);
			$data['mobile']  = $_P['mobile'];
		}
		if($auth['error'] != 0){
			$random = rand(5,10);
			sleep($random);
		}
		if (! empty($id)) {
			if($_G['isSuperAdmin']){
				if ($theme['refundfee']>0 && intval($_P['refundfee'])<1){
					return_msg('退款权限已开最小为1，不可关闭');
				}
				$data['uid'] = intval($_P['uid']);
				
				// $data ['chongzhi'] = sprintf("%.2f",floatval($_P['chongzhi'])-floatval($_P['tixian']));
				// $data ['jiezhang'] = $_P['jiezhang'];
				$data ['refundfee'] = intval($_P['refundfee']);
				$data ['isautorefund'] = intval($_P['isautorefund']);
				$data ['whitelist'] = $_P['whitelist'];
			}
			if($auth['error'] == 0){
                Theme_mod::update($id,$data);
			}
		} else {
			if ($_G['isSuperAdmin']){
				$data['uid'] = intval($_P['uid']);
				
				if (!empty($_G['mpid'])) {
                            $data ['uniacid'] = $_G['mpid'];
                        }
				// $data ['jiezhang'] = $_P['jiezhang'];
				$data ['refundfee'] = intval($_P['refundfee']);
				$data ['isautorefund'] = intval($_P['isautorefund']);
				$data ['softkey'] = Util::getRandomStr(9);
				$data ['whitelist'] = $_P['whitelist'];
			}else{
				$data['uid'] = $_G['uid'];
				$data ['uniacid'] = $_G['mpid'];
			}
			db_insert ( t_theme, $data );
			$id = $insertid;

			//生成短网址保存
			// if ($system['wxapp']==0) {
			// 	if (!empty($config['addworkerurl']) && intval($_P['accountid'])==$theme['uniacid']) {
			//     	$indexurl = $config['indexurl'];
			//     	$dapingurl = $config['dapingurl'];
			//     	$addworkerurl = $config['addworkerurl'];
			//     }else{
			// 		$indexurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('index',array('themeid'=>$id));
			// 		$indexurl = Poster::GetMainUrl($system,$indexurl,MODULE_NAME . '主网址');

			// 		$dapingurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('w_daping',array('themeid'=>$id));
			// 		$dapingurl = Poster::GetMainUrl($system,$dapingurl,MODULE_NAME . '添加投屏网址');

			// 		$addworkerurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('w_init',array('themeid'=>$id));
			// 		$addworkerurl = Poster::GetMainUrl($system,$addworkerurl,MODULE_NAME . '添加员工网址');
			// 	}
			// }else{
			// 	if (!empty($config['addworkerurl']) && intval($_P['accountid'])==$theme['uniacid']) {
			//     	$indexurl = $config['indexurlxcx'];
			//     	$dapingurl = $config['dapingurlxcx'];
			//     	$addworkerurl = $config['addworkerurlxcx'];
			//     }else{
	  //               $scene = "?softname=" . MODULE_NAME . "&themeid=" . $id . "&softkey=" . $theme['softkey'] ;
		 //            $indexurl = Poster::CreateXcxqr($system,'','pages/index/index' . $scene);
		 //            $addworkerurl = Poster::CreateXcxqr($system,'','pages/w_init/w_init' . $scene);

			// 		$dapingurl = $_G['url_scheme'] . $domaintxt.'/'.createMobileUrl('w_daping',array('themeid'=>$id));
			// 		$dapingurl = Poster::GetMainUrl($system,$dapingurl,MODULE_NAME . '添加投屏网址');
			// 	}
			// }

			if ($system['tixing']==1 && $theme['status']==1) {
				if (!empty($config['addworker_qrimg1'])) {
			    	$addworker_qrimg = $config['addworker_qrimg1'];
			    }else{
					//易宣服务器
					$data = array(
						'server'  => DOMAIN0,
						'softname'  => MODULE_NAME,
				        'uniacid' 	=> $_G['mpid'],
						'themeid' 	=> $id,
						'softkey' 	=> $theme['softkey'],
						'title' 	=> $theme['title'],
						'company' 	=> $theme['jubf'],				
						'desc' 	=> $theme['desc'],
						'endtime' 	=> $theme['endtime'],
						'headlogo' 	=> $theme['headlogo'],
					);
					$qr = Poster::ServerQR($system,'get',$data);
				    $addworker_qrimg = $qr['qrimg'];
			    }
			    $addworker_qrimg1 = $addworker_qrimg;
			}elseif ($system['tixing']==3 && $theme['status']==1) {
				if (!empty($config['addworker_qrimg2'])) {
			    	$addworker_qrimg = $config['addworker_qrimg2'];
			    }else{
					//客户公众平台
				    $qr = getQR($system,$domaintxt,$themeid,$theme['softkey']); 
				    $addworker_qrimg = $qr['qrimg_addworker'];
				    if (is_error($qr)) {
				        $result['code'] = 0;
				        $result['message'] = $qr["message"];
				        die(json_encode($result));
				        exit;
				    }
				}
			    $addworker_qrimg2 = $addworker_qrimg;			
			}

		}

		if (!empty($_P['softsn']) && $_G['isSuperAdmin'] ) {
			$data = array ();
			$softsndata = array(
				'software'    => MODULE_NAME,
	            'uniacid'  => $_G['mpid'],
				'themeid' => $id,
				'user' => $_G['username'],
				'softsn' => trim($_P['softsn']),
				'endtime' => $endtime,
			);
			$banklist = Poster::Getbanklist($system,'savesoftsn',$softsndata);
			if (!empty($banklist) && $banklist['error'] == 0) {
				if ($system['ruanjian'] =='3'){
					if (strstr($banklist['pricename'],"异业")==false ){
						$data['softsn']='';
			            Theme_mod::update($id,$data);
						return_msg('激活失败:异业模式未授权,实际定单为:' . $banklist['pricename']);
					}
				}
				$data['softsn'] = trim($_P['softsn']);
				$data['softqubanquan']=intval($banklist['softqubanquan']);
				$data['softoem']=intval($banklist['softoem']);
				$data['jubf']=$banklist['jubf'];
		    	$config['province'] = $banklist['province'];
		    	$config['city'] = $banklist['city'];
		    	$config['district'] = $banklist['district'];
				if ($data['softqubanquan'] == 1) {
			        $data['yixuanbanquan'] = $_P['yixuanbanquan'];
				}
				if ($data['softoem'] == 1) {
			        $data['yixuanbanquan'] = $_P['yixuanbanquan'];
					$data['USERURL'] = $_P['USERURL'];
					$data['USERJISHU'] = $_P['USERJISHU'];
					$data['USERCOMPANYNAME'] = $_P['USERCOMPANYNAME'];
				}
				$data['banmian']=intval($banklist['banmian']);
	            Theme_mod::update($id,$data);
			}else{
				$data['softsn']='';
				$data['softqubanquan']=0;
				$data['softoem']=0;
	            Theme_mod::update($id,$data);
				return_msg('激活失败:'.$banklist['msg']);
			}
		}

		$buttontyle = intval($_P['buttontyle']);
		if ($buttontyle==0 && !empty($_P['formcolortop'])){
			$formcolortop = $_P['formcolortop'];
			$formcolorhead  = $_P['formcolorhead'];
			$formcolorcenter  = $_P['formcolorcenter'];
			$formcolorlefttext = $_P['formcolorlefttext'];
			$formcolorcentertext = $_P['formcolorcentertext'];
			$formcolorrighttext =  $_P['formcolorrighttext'];
			$starbgcolor = $_P['starbgcolor'];
			$starbtcolor = $_P['starbtcolor'];
			$startextcolor = $_P['startextcolor'];
		}else{
			if ($buttontyle==1){
				$formcolorhead  = "#62d4f5";
				if ($system['ruanjian']==2) {
					$formcolorcenter  = "#14bbdf";
				}else{
					$formcolorcenter  = "#087b9c";
				}
				$formcolortop = "#14bbdf";
				$formcolorlefttext = "#5d5a5a";
				$formcolorcentertext = "#ffffff";
				$formcolorrighttext =  "#ffffff";
			}elseif ($buttontyle==3){
				$formcolorhead  = "#ff8788";
				$formcolorcenter  = "#fed904";
				$formcolortop = "#fc3611";
				$formcolorlefttext = "#ffffff";
				$formcolorcentertext = "#615f5f";
				$formcolorrighttext =  "#ffffff";
			}else{
				$formcolorhead  = "#f36765";
				$formcolorcenter  = "#fed904";
				$formcolortop = "#ec1f1a";
				$formcolorlefttext = "#ffffff";
				$formcolorcentertext = "#615f5f";
				$formcolorrighttext =  "#ffffff";
			}
			$starbgcolor = "#ffffff";
			$starbtcolor =$formcolortop;
			$startextcolor =  $formcolorrighttext;
		}
		if ($system['gift']==1) {
			$groupid = intval($_P['giftgroupid']);
			if($groupid > 0){
				$result = db_find ( "SELECT count(*) as cnt FROM " . tablename ( t_gift ) . " WHERE state = 1 and giftgroupid = '{$groupid}' and uniacid = '{$_G['mpid']}'" );
				$giftsum = $result ['cnt'];
				if($giftsum <= 0){
					return_msg('所选礼品分组的礼品数量为0，请添加具体的礼品');
				}
				$giftselectsum = intval($_P['gifttypeselect1']);
				if($typeid == 1){
					$giftselectsum = 0;
				}else{
					if($giftselectsum <= 0){
						return_msg('任选模式下，礼品可选种数不可为0');
					}
					if($giftselectsum > $giftsum){
						return_msg('可选礼品种类总数需要小于等于分组内礼品总数！');
					}
				}
			}
		}

		//当团人数发生改变时,较正团的状态
		if(intval($_P['maxcount']) <> intval($_P['maxcountall'])-1){
			$recentlist = Record::getPayEdListByThemeId($themeid,50000);
			foreach ($recentlist as $index =>$row){
				if ($row['renshu']==1) {
					$neednum = intval($_P['maxcountall2'])-1;
				}else{
					$neednum = intval($_P['maxcountall'])-1;
				}
				
	            $details = Record::getAttendDetailNumByPId($row['id']);
	            db_update( t_record, array("tuannum"=>$details+1), array ('pid' => $recentlist[$index]['id']) );
	            $leftnum = $neednum-$details;
	            if ( $leftnum <= 0 ) {
	            	Record::setIsfinish($recentlist[$index]['id']);
	            }else{
	            	Record::setNofinish($recentlist[$index]['id']);
	            }

	        }
		}
		//点亮模式
		if (intval($_P['isicon'])==1){
			$iconnum2=0;
		}elseif (intval($_P['isicon'])==2){
			if (intval($_P['iconnum2'])<1){
				$iconnum2=1;
			}else{
				$iconnum2=intval($_P['iconnum2']);
			}
		}else{
			$iconnum2=intval($_P['iconnum2']);
		}
		if ($system['ruanjian']==0 && $system['softstyle']==5) {
			$address = "加盟地区";
		}else{
			$address = trim($_P['address']);
		}
		if (empty($_P['nametext'])) {
			$nametext = "姓名";
		}else{
			$nametext = $_P['nametext'];
		}
		if (empty($_P['mobiletext'])) {
			$mobiletext = "电话";
		}else{
			$mobiletext = $_P['mobiletext'];
		}
		if (sprintf("%.2f",floatval($_P['joinfee']))!=='0.00') {
			$formtextcenter = $_P['formtextcenter'];
			$formtextcenter2 = $_P['formtextcenter2'];
			$formtextcenternew = $_P['formtextcenternew'];
			$formtextright = $_P['formtextright'];
			$formtextcenterxcx = $_P['formtextcenterxcx'];
			$formtextcenter2xcx = $_P['formtextcenter2xcx'];
			$formtextcenternewxcx = $_P['formtextcenternewxcx'];
			$formtextrightxcx = $_P['formtextrightxcx'];		
		}else{
			$formtextcenter = str_replace("#fee","#tuan",$_P['formtextcenter']);
			$formtextcenter2 = str_replace("#fee","#tuan",$_P['formtextcenter2']);
			$formtextcenternew = str_replace("#fee","#tuan",$_P['formtextcenternew']);
			$formtextright = str_replace("#fee","#tuan",$_P['formtextright']);
			$formtextcenterxcx = str_replace("#fee","#tuan",$_P['formtextcenterxcx']);
			$formtextcenter2xcx = str_replace("#fee","#tuan",$_P['formtextcenter2xcx']);
			$formtextcenternewxcx = str_replace("#fee","#tuan",$_P['formtextcenternewxcx']);
			$formtextrightxcx = str_replace("#fee","#tuan",$_P['formtextrightxcx']);
		}
		if (empty($_P['shopsmin'])) {
			$shopsmin = 1;
		}else{
			$shopsmin = intval($_P['shopsmin']);
		}
		if (empty($_P['shopsmax'])) {
			$shopsmax = 1;
		}else{
			$shopsmax = intval($_P['shopsmax']);
		}
		$gudingoptions = $_P['gudingoptions'][0];
		if (empty($gudingoptions)) {
			$gudingoptions = '';
		}else{
			$gudingoptions = $_P['gudingoptions'];
		}

		if (($isold && $_G['isSuperAdmin']) || !$isold) {
			$bannerimgs = $_P['bannerimgs'];
			if (!empty($bannerimgs)) {
				foreach ($bannerimgs as $key => $value) {
					$bannerimgs[$key]=tomedia($value);
				}
			}
			$centerimgs = $_P['centerimgs'];
			if (!empty($centerimgs)) {
				foreach ($centerimgs as $key => $value) {
					$centerimgs[$key]=tomedia($value);
				}
			}
			$imgs = $_P['imgs'];
			if (!empty($imgs)) {
				foreach ($imgs as $key => $value) {
					$imgs[$key]=tomedia($value);
				}
			}
			$content = htmlspecialchars_decode($_P['content']);
			$videoimgs = $_P['videoimgs'];
			if (!empty($videoimgs)) {
				$videocount= substr_count($content,'<video');
				$start = 0;
				$strlength = strlen($content)+1000;
				$contentnew="";
				// echo "原文" . $content;
				// echo "\n\n\n\n";
				foreach ($videoimgs as $key => $value) {					
					$videoimgs[$key]=tomedia($value);
					$videologo=tomedia($value);
					$videologo = str_replace("/99.jpg", "/video.jpg", $videologo);
					if ($start==0) {
						$temp0 = "";
						$end = strpos($content,"/web/resource/images/player.jpg")+50;
						$temp1 = substr($content, $start, $end);
					}else{
						// echo "temp2". $temp2."\n\n\n\n";
						$end = strpos($temp2,"/web/resource/images/player.jpg")+50;
						$temp1 = substr($temp2, 0, $end);
						$end = $end+$start ;	
					}
					$temp2 = substr($content, $end, $strlength);
					// echo $start ."temp1". $temp1."\n\n\n\n";				
					$temp1 = str_replace("http://" . $_SERVER['HTTP_HOST'] . "/web/resource/images/player.jpg", $videologo, $temp1);
					$temp1 = str_replace("https://" . $_SERVER['HTTP_HOST'] . "/web/resource/images/player.jpg", $videologo, $temp1);

					$start =  $end;	
					$contentnew .= $temp1;
					// 		echo "\n\n\n\n";
					// 		echo "结果". $key. $contentnew;
					// 		echo "\n\n\n\n";
				}
				// echo "temp2". $temp2."\n\n\n\n";
				// echo "\n\n\n\n";
				// echo "结果". $contentnew . $temp2;
				// echo "\n\n\n\n";
				$content = $contentnew . $temp2;
				// echo $content;
				$content = str_replace("width=\"300\" height=\"200\"", "width=\"100%\" height=\"auto\"", $content);
			}

			$tuwen = array(
				'content'     => $content,
				'livecontent'     =>  htmlspecialchars_decode($_P['livecontent']),
				'headlogo'    => tomedia($headlogo),
				'liveheadlogo'    => tomedia($_P['liveheadlogo']),
				'bannervideo'    => tomedia($_P['bannervideo']),
				'bannerimgs'  => $bannerimgs,
				'centerimgs'  => $centerimgs,
				'imgs'        => $imgs,
				'kfewm'      => tomedia($_P['kfewm']),
				'addresstxt'       => $_P['addresstxt'],
				'zhuandantxt'       => $_P['zhuandantxt'],
				'zhuandantips'       => $_P['zhuandantips'],
                'zhuandanbegintime'=>strtotime($_P['zhuandantime']['start']),
                'zhuandanendtime'=>strtotime($_P['zhuandantime']['end']),
			);
		}else{ 
			$tuwen = $config;
			$tuwen = array(
				'content'     => $tuwen['content'],
				'livecontent'     => $tuwen['livecontent'],
				'headlogo'    => $tuwen['headlogo'],
				'liveheadlogo'    => $tuwen['liveheadlogo'],
				'bannervideo'    => $tuwen ['bannervideo'],
				'bannerimgs'  => $bannerimgs,
				'centerimgs'  => $tuwen ['centerimgs'],
				'imgs'        => $tuwen['imgs'],
				'kfewm'      => $tuwen ['kfewm'],
				'addresstxt'       => $tuwen ['addresstxt'],
				'zhuandantxt'       => $tuwen ['zhuandantxt'],
				'zhuandantips'       => $tuwen ['zhuandantips'],
                'zhuandanbegintime' => $tuwen ['zhuandanbegintime'],
                'zhuandanendtime' => $tuwen ['zhuandanendtime'],
			);
			$isoldtips=",图文内容未更新";
		}
		if ($_G['isSuperAdmin']) {
			$wuxian = intval($_P['wuxian']);
			$weixinh5 = intval($_P['weixinh5']);
			$iswxshare = intval($_P['iswxshare']);
		}else{
			$wuxian = $config ['wuxian'];
			$weixinh5 = $config ['weixinh5'];
			$iswxshare = $config ['iswxshare'];
		}
		$shopstype = intval($_P['shopstype']);
		if ($shopstype == 5) {
			$shopstype = 4;
			$shopstype5 = 1;
			$options = array();
			foreach ($shoplist as $index => $row) {
				array_push($options,$row['name']);
			}
		}else{
			$shopstype5 = 0;
			$options = $_P['options'];
		}		
		$config = array(
                'videotime'    =>$config['videotime'],
                'province'    =>$config['province'], 
                'city'    =>$config['city'],
                'district'    =>$config['district'],
                'indexurl'    =>$config['indexurl'],
                'dapingurl'    =>$config['dapingurl'],
                'addworkerurl'    =>$config['addworkerurl'],
                'addworkerurlxcx'    =>$config['addworkerurlxcx'],
                'indexurlxcx'    =>$config['indexurlxcx'],
                'addworker_qrimg1'    =>$addworker_qrimg1,
                'addworker_qrimg2'    =>$addworker_qrimg2,
                'softtag0'    =>$softtag0,
                'softtag1'    =>$softtag1,
                'softtag2'    =>$softtag2,
				'content'     => $tuwen['content'],
				'contentxcx'     => Poster::getContentvideoimg($tuwen['content']),
				'livecontentxcx'     =>  Poster::getContentvideoimg($tuwen['livecontent']),
				'livecontent'     => $tuwen['livecontent'],
				'headlogo'    => $tuwen['headlogo'],
				'liveheadlogo'    => $tuwen['liveheadlogo'],
				'bannervideo'    => $tuwen['bannervideo'],
				'bannerimgs'  => $tuwen ['bannerimgs'],
				'centerimgs'  => $tuwen ['centerimgs'],
				'imgs'        => $tuwen['imgs'],
				'videoimgs'  => $videoimgs,
				'kfewm'      => $tuwen ['kfewm'],
				'addresstxt'       => $tuwen ['addresstxt'],
				'zhuandantxt'       => $tuwen ['zhuandantxt'],
				'zhuandantips'       => $tuwen ['zhuandantips'],
                'zhuandanbegintime' => $tuwen ['zhuandanbegintime'],
                'zhuandanendtime' => $tuwen ['zhuandanendtime'],

                'isgrouper'    => trim($_P['isgrouper']),
                'isform'       => trim($_P['isform']),
                'ingcolor'     => trim($_P['ingcolor']),
                'successcolor' => trim($_P['successcolor']),
                'payedurl'     => trim($_P['payedurl']),
		        'istime'        =>intval($_P['istime']),
		        'iswttouxiang'        =>intval($_P['iswttouxiang']),
                'groupprice'    => sprintf("%.2f",floatval($_P['groupprice'])),
                'groupprice2'    => sprintf("%.2f",floatval($_P['groupprice2'])),
                'primeprice'    => sprintf("%.2f",floatval($_P['primeprice'])),
                'marketprice'    => sprintf("%.2f",floatval($_P['marketprice'])),
                'submittxt'     => trim($_P['submittxt']),
		        'iscode'        => intval($_P['iscode']),
                'recentstyle'   => intval($_P['recentstyle']),
                'headstyle'     => intval($_P['headstyle']),
                'tuanrank'     => intval($_P['tuanrank']),
                'fansrank'     => intval($_P['fansrank']),
                'fcfootmenu'     => intval($_P['fcfootmenu']),
                'code_title'    => trim($_P['code_title']),
                'code_pwd'      => trim($_P['code_pwd']),
                'code_tips'     => trim($_P['code_tips']),
                'code_ing'      => trim($_P['code_ing']),
                'code_end'      => trim($_P['code_end']),
				'isposter'      => trim($_P['isposter']),
                'postericon'    => trim($_P['postericon']),
                'isyzmember'    => trim($_P['isyzmember']),
		        'kficon'      => trim($_P['kficon']),
		        'ordericon'   => trim($_P['ordericon']),
                'formcolor'   => trim($_P['formcolor']),
                'workerpass'   => trim($_P['workerpass']),
                'isshow'      => intval($_P['isshow']),
				'istzcy'      => intval($_P['istzcy']),
				'istycy'      => intval($_P['istycy']),
				'isopen'      => intval($_P['isopen']),
				'isdanmu'     => intval($_P['isdanmu']),
				'danmu01'     => intval($_P['danmu01']),
				'danmu02'     => intval($_P['danmu02']),
				'danmu03'     => intval($_P['danmu03']),
				'danmu04'     => intval($_P['danmu04']),
				'isreply'     => intval($_P['isreply']),
				'isaudit'     => intval($_P['isaudit']),
				'sharetip'    => tomedia($_P['sharetip']),
                'pinpailogo'    => tomedia($_P['pinpailogo']),

				'showpayresult'     => intval($_P['showpayresult']),
				'payway'      => 0 ,//intval($_P['payway']),
                'demo'        => trim($_P['demo']),
				'mappoint'         => trim($_P['mappoint']),

				'qrlistname1' => trim($_P['qrlistname1']),
				'qrlistname2' => trim($_P['qrlistname2']),
				'qrlistimgs'  => trim($_P['qrlistimgs']),
				'qrlistbufa'     => intval($_P['qrlistbufa']),
				'qrlistmode'     => intval($_P['qrlistmode']),
				//交易凭证
				// 'jubf'       => trim($_P['jubf']),
				//底部文字标签
				'lableunbegin' => trim($_P['lableunbegin']),
				'lableend'     => trim($_P['lableend']),
				'lablegroup'   => trim($_P['lablegroup']),
				'lablepygroup' => trim($_P['lablepygroup']),
				'lablecjgroup' => trim($_P['lablecjgroup']),
				'lablegspy'    => trim($_P['lablegspy']),
				'lablesuccess' => trim($_P['lablesuccess']),
                'lablegoon'    => trim($_P['lablegoon']),
				'lableleadergs'=> trim($_P['lableleadergs']),
				'limitcity'    => trim($_P['limitcity']),
				'url'           => trim($_P['url']),
				'color'         => trim($_P['color']),
                'isgoon'        => intval($_P['isgoon']),
				//现金红包

                'hbtixian'      => floatval($_P['hbtixian']),
                'hbopentips'      => tomedia($_P['hbopentips']),
                'zhuandanimg'      => tomedia($_P['zhuandanimg']),
                'viewcity'         => trim($_P['viewcity']),
                'viewcitywhitelist'         => trim($_P['viewcitywhitelist']),  
                
                'hbtixianmode'        => intval($_P['hbtixianmode']),
                'hbopenfee1'      => floatval($_P['hbopenfee1']),
                'hborderfee1'      => floatval($_P['hborderfee1']),
                'hbopenfee2'      => floatval($_P['hbopenfee2']),
                'hborderfee2'      => floatval($_P['hborderfee2']),

                'comm61'      => floatval($_P['comm61']),
                'comm62'      => floatval($_P['comm62']),
                'comm11'      => floatval($_P['comm11']),
                'comm12'      => floatval($_P['comm12']),
                'comm13'      => intval($_P['comm13'])==0?100:intval($_P['comm13']),

                'comm11_2'      => floatval($_P['comm11_2']),
                'comm12_2'      => floatval($_P['comm12_2']),
                'comm13_2'      => intval($_P['comm13_2'])==0?100:intval($_P['comm13_2']),
                'comm11_3'      => floatval($_P['comm11_3']),
                'comm12_3'      => floatval($_P['comm12_3']),

				'comm1'       => floatval($_P['comm11']),
				'comm2'       => floatval($_P['comm12']),
                'comm21'      => floatval($_P['comm21']),
                'comm22'      => floatval($_P['comm22']),
                'comm21_2'      => floatval($_P['comm21_2']),
                'comm22_2'      => floatval($_P['comm22_2']),
                'comm23'      => intval($_P['comm23'])==0?100:intval($_P['comm23']),
                'comm31'      => floatval($_P['comm31']),
                'comm32'      => floatval($_P['comm32']),
                'comm31_2'      => floatval($_P['comm31_2']),
                'comm32_2'      => floatval($_P['comm32_2']),
                'comm33'      => intval($_P['comm33'])==0?100:intval($_P['comm33']),

                'comm61_jiage2'      => floatval($_P['comm61_jiage2']),
                'comm62_jiage2'      => floatval($_P['comm62_jiage2']),
                'comm11_jiage2'      => floatval($_P['comm11_jiage2']),
                'comm12_jiage2'      => floatval($_P['comm12_jiage2']),
				'comm1_jiage2'       => floatval($_P['comm11_jiage2']),
				'comm2_jiage2'       => floatval($_P['comm12_jiage2']),
                'comm21_jiage2'      => floatval($_P['comm21_jiage2']),
                'comm22_jiage2'      => floatval($_P['comm22_jiage2']),
                'comm31_jiage2'      => floatval($_P['comm31_jiage2']),
                'comm32_jiage2'      => floatval($_P['comm32_jiage2']),

                'comm61_jiage3'      => floatval($_P['comm61_jiage3']),
                'comm62_jiage3'      => floatval($_P['comm62_jiage3']),
                'comm11_jiage3'      => floatval($_P['comm11_jiage3']),
                'comm12_jiage3'      => floatval($_P['comm12_jiage3']),
				'comm1_jiage3'       => floatval($_P['comm11_jiage3']),
				'comm2_jiage3'       => floatval($_P['comm12_jiage3']),
                'comm21_jiage3'      => floatval($_P['comm21_jiage3']),
                'comm22_jiage3'      => floatval($_P['comm22_jiage3']),
                'comm31_jiage3'      => floatval($_P['comm31_jiage3']),
                'comm32_jiage3'      => floatval($_P['comm32_jiage3']),

                'comm41'      => floatval($_P['comm41']),
                'comm42'      => floatval($_P['comm42']),
                'comm43'      => intval($_P['comm43'])==0?100:intval($_P['comm43']),
                'comm41_2'      => floatval($_P['comm41_2']),
                'comm42_2'      => floatval($_P['comm42_2']),
                'comm43_2'      => intval($_P['comm43_2'])==0?100:intval($_P['comm43_2']),
                'comm41_3'      => floatval($_P['comm41_3']),
                'comm42_3'      => floatval($_P['comm42_3']),
				'comm4daynum'    => intval($_P['comm4daynum']),
				'comm4sum'   => intval($_P['comm4sum']),

                'comm51'      => floatval($_P['comm51']),
                'comm52'      => floatval($_P['comm52']),
                'comm53'      => intval($_P['comm53'])==0?100:intval($_P['comm53']),
                'comm51_2'      => floatval($_P['comm51_2']),
                'comm52_2'      => floatval($_P['comm52_2']),
                'comm53_2'      => intval($_P['comm53_2'])==0?100:intval($_P['comm53_2']),
                'comm51_3'      => floatval($_P['comm51_3']),
                'comm52_3'      => floatval($_P['comm52_3']),
				'comm5daynum'    => intval($_P['comm5daynum']),
				'comm5sum'   => intval($_P['comm5sum']),

                'comm7num'      => intval($_P['comm7num']),
                'comm7fee'      => floatval($_P['comm7fee']),
				'lipinoptions'     => $_P['lipinoptions'],
                'comm711'      => floatval($_P['comm711']),
                'comm712'      => floatval($_P['comm712']),
                'comm71type'      => intval($_P['comm71type']),
                'comm721'      => floatval($_P['comm721']),
                'comm722'      => floatval($_P['comm722']),
                'comm72type'      => intval($_P['comm72type']),
                'comm731'      => floatval($_P['comm731']),
                'comm732'      => floatval($_P['comm732']),
                'comm73type'      => intval($_P['comm73type']),
                'comm741'      => floatval($_P['comm741']),
                'comm742'      => floatval($_P['comm742']),
                'comm74type'      => intval($_P['comm74type']),
                'comm751'      => floatval($_P['comm751']),
                'comm752'      => floatval($_P['comm752']),
                'comm75type'      => intval($_P['comm75type']),
                
                'getavatar'      => intval($_P['getavatar']),
                'getmobile'      => intval($_P['getmobile']),
                'comm4dashuju'      => intval($_P['comm4dashuju']),
                'comm4autored'      => intval($_P['comm4autored']),
                'comm4autoredtime'=> strtotime($_P['comm4autoredtime']),
                'comm4tips'  => trim($_P['comm4tips']),
                'comm4ziliao'  => trim($_P['comm4ziliao']),
				'iscomm'      => intval($_P['iscomm']),
				'iscommshowworker'      => intval($_P['iscommshowworker']),
				'isfansrankshowworker'      => intval($_P['isfansrankshowworker']),
				'commtoger'   => intval($_P['commtoger']),
                'iscommshow'  => trim($_P['iscommshow']),
                'commlistimg' => tomedia($_P['commlistimg']),
                'commlistimgbg' => tomedia($_P['commlistimgbg']),
				'commlistbg1'     => empty($_P['commlistbg1']?'#fee567':$_P['commlistbg1']),
				'commlistbg2'     => empty($_P['commlistbg1']?'#fffaef':$_P['commlistbg2']),


				'iconimg'     => trim($_P['iconimg']),
				'iconziliao'     => intval($_P['iconziliao']),
					
				'sharetitle1'=> trim($_P['sharetitle1']),
				'sharetitle2'=> trim($_P['sharetitle2']),
				'sharetitle3'=> trim($_P['sharetitle3']),

				'sharetitlexcx'=> trim($_P['sharetitlexcx']),
				'sharetitlexcx2'=> trim($_P['sharetitlexcx2']),
				'shareimgxcx'    => tomedia($_P['shareimgxcx']),
				
				'livedata' => array(
					'liveid' =>  intval($_P["lid"]),
					'livetime' => strtotime($_P["livetime"]),
					'lname' => trim($_P['lname']),
					'relive' => trim($_P['relive']),
					'livestatus' => intval($_P['livestatus']),
					'sendnotify' => trim($_P['sendnotify']),
					'yure' => intval($_P['yure'])
				),
				
				'tel'        => trim($_P['tel']),
				'adv2live2'  => trim($_P['adv2live2']),
				'liveid'     => trim($_P['liveid']),
				'seturl'      => trim($_P['seturl']),
				//底部下方
				'address'     => $address,
				'shops'       => trim($_P['shops']),
				'shopsmin'     => empty($shopsmin)?$config['shopsmin']:$shopsmin,
				'shopsmax'     => empty($shopsmax)?$config['shopsmax']:$shopsmax,
				'options'     => $options,
				'gudingoptions'     => $gudingoptions,
				'blefttip'    => trim($_P['blefttip']),
				'bshare'      => trim($_P['bshare']),
				'themelxr'    => trim($_P['themelxr']),
				'status'      => intval($_P['status']),
		        'datetime'    => trim($_P['datetime']),
				
				'musicsrc'    => tomedia($_P['musicsrc']),
				'automusic'   => intval($_P['automusic']),
				'iswxshare'   => $iswxshare,
				'weixinh5'   => $weixinh5,
				
				
				//点亮图标相关
                'todayicon'  => intval($_P['todayicon']),
				'isicon'      => intval($_P['isicon']),
                'iconlimit'  => intval($_P['iconlimit']),
                'iconlimituser'  => intval($_P['iconlimituser']),
				'darkicon'    => tomedia($_P['darkicon']),
				'lighticon'   => tomedia($_P['lighticon']),
				'iconname'    => trim($_P['iconname']),
				'iconlogo'     => intval($_P['iconlogo']),
				'iconnum'     => intval($_P['iconnum']),
                'iconnum2'     => $iconnum2,
				'icongift'    => trim($_P['icongift']),
				'gifttip'    => trim($_P['gifttip']),
				'icongiftsum' => intval($_P['icongiftsum']),
				'iconrange'   => intval($_P['iconrange']),
					
				'commcolor'  => trim($_P['commcolor']),
				'groupsum'   => intval($_P['groupsum']),
					
				'detailsex'  => intval($_P['detailsex']),
				'groupsex'   => intval($_P['groupsex']),
					
				//支付换取礼品
				'maxcount'   => intval($_P['maxcountall'])-1,
				'isrecent'   => intval($_P['isrecent']),
				'issearch'   => intval($_P['issearch']),
				
				
				'duojiagetips'  => trim($_P['duojiagetips']),
                'joinfee'    => sprintf("%.2f",floatval($_P['joinfee'])),
				'joinname'  => trim($_P['joinname']),
                'joinfee2'    => sprintf("%.2f",floatval($_P['joinfee2'])),
				'joinname2'  => trim($_P['joinname2']),
                'joinfee3'    => sprintf("%.2f",floatval($_P['joinfee3'])),
				'joinname3'  => trim($_P['joinname3']),


				'maxcountall'   => intval($_P['maxcountall']),	
				'maxcountall2'   => intval($_P['maxcountall2']),	
				'maxcountall3'   => intval($_P['maxcountall3']),	
				'maxcountall4'   => intval($_P['maxcountall4']),	
				'maxcountall5'   => intval($_P['maxcountall5']),				
				'groupneedtime'   => intval($_P['groupneedtime']),		
				'groupautotime'   => intval($_P['groupautotime']),

				'formcolortop'  => $formcolortop,
				'formcolorhead'  => $formcolorhead,
				'formcolorcenter'  => $formcolorcenter,
				'formcolorlefttext'  => $formcolorlefttext,
				'formcolorcentertext'  => $formcolorcentertext,
				'formcolorrighttext'  => $formcolorrighttext,
				
				'starbgcolor'  => $starbgcolor,
				'starbtcolor'  => $starbtcolor,
				'startextcolor'  => $startextcolor,
					
				'formtextleftopen'   => intval($_P['formtextleftopen']),
				'formtextleft'    => trim($_P['formtextleft']),
				'formtextcenter'    => $formtextcenter,
				'formtextcenter2'    => $formtextcenter2,
				'formtextcenternew'    => $formtextcenternew,
				'formtextright'    => $formtextright,

				'formtextleftxcx'    => trim($_P['formtextleftxcx']),
				'formtextcenterxcx'    => $formtextcenterxcx,
				'formtextcenter2xcx'    => $formtextcenter2xcx,
				'formtextcenternewxcx'    => $formtextcenternewxcx,
				'formtextrightxcx'    => $formtextrightxcx,

				'formtextpay'    => trim($_P['formtextpay']),	
				'isfreeze'   => intval($_P['isfreeze']),
				'intheme'   => intval($_P['intheme']),
				'comm4city'    => trim($_P['comm4city']),
				'comm4type'   => intval($_P['comm4type']),
				'comm4typehb'   => intval($_P['comm4typehb']),
				'comm4typeyg'   => intval($_P['comm4typeyg']),
				'locationtype'   => intval($_P['locationtype']),
				'comm4day'   => intval($_P['comm4day']),
				'comm4hour'   => intval($_P['comm4hour']),
				'comm4ip'   => intval($_P['comm4ip']),
				'comm4sharetime'   => intval($_P['comm4sharetime']),
				'comm4yaotime'   => intval($_P['comm4yaotime']),
				'commworker'   => intval($_P['commworker']),
				'fenxiaotip'    => tomedia($_P['fenxiaotip']),
				'fenxiaourl'    => intval($_P['fenxiaourl']),
				
				'yaoyiyaotip'    => tomedia($_P['yaoyiyaotip']),

				'comm4time'   => intval($_P['comm4time']),
				'comm4friend'   => intval($_P['comm4friend']),
				'comm4worker'   => intval($_P['comm4worker']),

				'iscommshow24'   => intval($_P['iscommshow24']),
				'isshowprice'   => intval($_P['isshowprice']),
				'comm4ispay'   => intval($_P['comm4ispay']),
				'isshowkefu'   => intval($_P['isshowkefu']),
				
				'isrankrenshu'   => intval($_P['isrankrenshu']),
				'isrankqianshu'   => intval($_P['isrankqianshu']),
				'ismycomm'   => intval($_P['ismycomm']),
				'ishbicon'   => intval($_P['ishbicon']),
				'hbtip'    => tomedia($_P['hbtip']),
				
				'buttontips'    => trim($_P['buttontips']),
				'dandutips'    => trim($_P['dandutips']),
				'pintuantips'    => trim($_P['pintuantips']),
				'pintuantips2'    => trim($_P['pintuantips2']),
				
				'fakejoin'    => intval($_P['fakejoin']),
				'fakescan'    =>intval($_P['fakescan']),
				'faketuan'    =>intval($_P['faketuan']),
				'touxiang'    =>intval($_P['touxiang']),
				'isshowname'    =>intval($_P['isshowname']),
				'nametext'    => $nametext,
				'mobiletext'    => $mobiletext,
				'iconhang'    =>intval($_P['iconhang']),
				'iscommshowfail'    =>intval($_P['iscommshowfail']),
				'iscommshowwait'    =>intval($_P['iscommshowwait']),
				'ishexiao'   => intval($_P['ishexiao']),
				'showshop'   => intval($_P['showshop']),
				'showalldata'   => intval($_P['showalldata']),
				'homeshowshop'   => intval($_P['homeshowshop']),
				'duoshangjiashouye'   => intval($_P['duoshangjiashouye']),	
				'duoshangjiaheigh'   => intval($_P['duoshangjiaheigh']),				
				'todaytime' => intval($_P['todaytime']),
				'xieyi'    => trim($_P['xieyi']),

                'formtitle'  => trim($_P['formtitle']),	
                'formimg'  => tomedia($_P['formimg']),	
				'formtourl' => intval($_P['formtourl'])=='-1'?$id:intval($_P['formtourl']),

				'isexampleqr'   => intval($_P['isexampleqr']),
				'examplestyle'   => intval($_P['examplestyle']),
				'tuanmode'   => intval($_P['tuanmode']),
				'datetimetype'   => intval($_P['datetimetype']),
				'shopstype'   => $shopstype,
				'shopstype5'   => $shopstype5,

				'addresstype'   => intval($_P['addresstype']),
				'addressoptions'     => $_P['addressoptions'],

				'jmdibuwenzi'    => trim($_P['jmdibuwenzi']),
				'jmzhifuwenzi'    => trim($_P['jmzhifuwenzi']),
				'jmbiemingwenzi'    => trim($_P['jmbiemingwenzi']),
				'jmzhifuwenzi'    => trim($_P['jmzhifuwenzi']),
				'jmlablesuccess'    => trim($_P['jmlablesuccess']),

				'jmdibuwenzi2'    => trim($_P['jmdibuwenzi2']),
				'jmzhifuwenzi2'    => trim($_P['jmzhifuwenzi2']),
				'jmbiemingwenzi2'    => trim($_P['jmbiemingwenzi2']),
				'jmzhifuwenzi2'    => trim($_P['jmzhifuwenzi2']),


				'jmformtextleft'    => trim($_P['jmformtextleft']),
				'jmlocktext'    => trim($_P['jmlocktext']),
				'jmbottompay'    => trim($_P['jmbottompay']),
				'jmformtextpay'    => trim($_P['jmformtextpay']),
				'jmlablesuccess2'    => trim($_P['jmlablesuccess2']),
				'jmlogo'    => tomedia($_P['jmlogo']),
				'jmkefuimg'    => tomedia($_P['jmkefuimg']),
				'jmnumimg'    => tomedia($_P['jmnumimg']),
				'jmcityimg'    => tomedia($_P['jmcityimg']),
				'jmcontent'     => htmlspecialchars_decode($_P['jmcontent']),

				'wtformtextleft'    => trim($_P['wtformtextleft']),
				'wtformtextpay'    => trim($_P['wtformtextpay']),
				'iconname_menu'    => trim($_P['iconname_menu']),
				'wtlablesuccess'    => trim($_P['wtlablesuccess']),
				'wtisshowmenu' => intval($_P['wtisshowmenu']),
				'yukuan' =>  sprintf("%.2f",floatval($_P['yukuan'])),
				'yukuantime' => strtotime($_P['yukuantime']),
				'yukuanfenxiao' => intval($_P['yukuanfenxiao']),

				'renshu' => intval($_P['renshu']),
				'renshumode' => intval($_P['renshumode']),
				'renshudanwei' => trim($_P['renshudanwei']),
				'renshutips' => trim($_P['renshutips']),
				'isreport' => intval($_P['isreport']),
				'iseditorder' => intval($_P['iseditorder']),
				'isrank' => intval($_P['isrank']),
				'isshoprank' => intval($_P['isshoprank']),
				'isxianxia' => intval($_P['isxianxia']),
				'isshowxianxia' => intval($_P['isshowxianxia']),
				'isworkerpay' => intval($_P['isworkerpay']),		

				'friendorder' => intval($_P['friendorder']),
				'friend_groupid' => intval($_P['friend_groupid']),
				'friend_name'    => trim($_P['friend_name']),
				'friend_unit'    => trim($_P['friend_unit']),
				'friend_anniu'    => trim($_P['friend_anniu']),
				'friend_success'    => trim($_P['friend_success']),
				'friend_wait'    => trim($_P['friend_wait']),
				'isshowtips'    => intval($_P['isshowtips']),

				'giftgroupid' => $groupid,
				'gifttypesum' => $giftsum,
				'gifttypeselect1' => intval($_P['gifttypeselect1']),
				'gifttypeselect2' => intval($_P['gifttypeselect2']),
				'showgift' => intval($_P['showgift']),
				'wuxian' => $wuxian,


				'fanpaigroupid' => intval($_P['fanpaigroupid']),
				'fanpaifanwei' => intval($_P['fanpaifanwei']),
				'fanpailimit' => intval($_P['fanpailimit']),
				'fanpaiweibaoming' => intval($_P['fanpaiweibaoming']),
				'fanpaibaoming' => intval($_P['fanpaibaoming']),
				'fanpaiyaoqing' => intval($_P['fanpaiyaoqing']),
				'fanpaipengyouquan' => intval($_P['fanpaipengyouquan']),
				'fanpai1day' => intval($_P['fanpai1day']),
				'fanpai2day' => intval($_P['fanpai2day']),
				'fanpai3day' => intval($_P['fanpai3day']),
				'fanpaijilu' => intval($_P['fanpaijilu']),
				'fanpaiimg' => trim($_P['fanpaiimg']),
				'fanpaibgcolor' => trim($_P['fanpaibgcolor']),			

		);

		writelog($id,'活动编辑',$config_old,$config,$_G['username']);
        $theme = Theme_mod::getById($id);
		writelog($id,'活动编辑',$theme_old,$theme,$_G['username']);
        Theme_mod::setConfig($config,$id,intval($_P['accountid']));
        //cache_clean();
        if($_G['isSuperAdmin'] && intval($_P['accountid'])!=$_G['mpid']){
        	$url = createWebUrl($do, array('op' => 'display'));
        	return_tips ( '公众平台已切换,请登录新公众平台查看！', $url, 'success' );
        }else{
        	$url = createWebUrl($do, array('op' => 'post','id'=>$id));
			return_tips ( '更新成功' . $isoldtips .'！', $url, 'success' );
        }
	}
}
if($auth['status']==120){
    die("");
}
$shouxu = 1 - Order::shouxufei();
$shouxu100 = Order::shouxufei()*100;

$return_clicent = get_defined_vars();
return view('/theme' , $return_clicent);
}
}